using System;
using System.Web.UI;
using Domain.Entities;

namespace UserInterface.UserControls
{
    public partial class AttachmentFileUpload : UserControl
    {
        private Attachment attachment;

        public event EventHandler Remove;

        protected void RemoveButton_Click(object sender, EventArgs e)
        {
            Remove(this, EventArgs.Empty);
        }
        
        public Attachment Attachment
        {
            get { return attachment; }
            set { attachment = value; }
        }

        public bool HasFile
        {
            get { return FileUpload.HasFile; }
        }

        public string FileName
        {
            get { return FileUpload.FileName; }
        }

        public int ContentLength
        {
            get { return FileUpload.PostedFile.ContentLength; }
        }

        public string ContentType
        {
            get { return FileUpload.PostedFile.ContentType; }
        }

        public void SaveAs(string path)
        {
            FileUpload.SaveAs(path);
        }

        protected void Page_PreRender(object sender, EventArgs e)
        {
            LocalIdLiteral.Text = attachment.LocalId.ToString();
        }
    }
}